golang/xenlight: Don't leak memory on context open failure
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 17 Jan 2020 14:01:05 +0000 (14:01 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 21 Jan 2020 17:48:24 +0000 (17:48 +0000)
commit682d0459c35d9a3616a6a5dfc03ac39d0dfe9e56
tree9e1ab2f8c99be7305efd5d78ece138b9309ed746
parent8ea9f5c56c0dfdd8089718fb86541b6025638328
golang/xenlight: Don't leak memory on context open failure

If libxl_ctx_alloc() returns an error, we need to destroy the logger
that we made.

Restructure the Close() method such that it checks for each resource
to be freed and then frees it.  This allows Close() to be come
idempotent, as well as to be a useful clean-up to a partially-created
context.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Nick Rosbrook <rosbrookn@ainfosec.com>
tools/golang/xenlight/xenlight.go